package com.json.entity;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Vector;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class AdImageBean {

	private String shopid;
	private String image;

	public String getLink() {
		return shopid;
	}

	public void setLink(String link) {
		this.shopid = link;
	}

	public String getLogo() {
		return image;
	}

	public void setLogo(String logo) {
		this.image = logo;
	}

	public static List<AdImageBean> fromXmlToAdroundInfo(Element root) {
		List<AdImageBean> list = new Vector<AdImageBean>(50);
		NodeList nlist = root.getElementsByTagName("result");
		for (int i = 0; i < nlist.getLength(); i++) {
			list.add(fromNode(nlist.item(i)));
		}
		return list;
	}

	private static AdImageBean fromNode(Node n) {
		AdImageBean ad = new AdImageBean();
		try {
			Class cls = ad.getClass();
			for (int i = 0; i < n.getChildNodes().getLength(); i++) {
				String fieldname = n.getChildNodes().item(i).getNodeName();
				Field field = cls.getDeclaredField(fieldname);
				field.set(ad, n.getChildNodes().item(i).getFirstChild()
						.getNodeValue());

			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ad;
	}

}
